package priv.pront.code.national.acwing.competition;

import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-05-27 22:04
 */
public class Acwing5029_极值数量 {

    static int cnt = 0;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if(n < 3){
            System.out.println(0);
            return;
        }
        int[] a = new int[n];
        for(int i = 0; i < n; i++){a[i] = scanner.nextInt();}

        for(int i = 1; i < n - 1; i++){
            int j = i - 1, k = i + 1;
            if(a[i] < a[j] && a[i] < a[k]){
                cnt++;
            }else if(a[i] > a[j] && a[i] > a[k]){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}
